package core.models;

import java.util.HashMap;
import java.util.Map;

public abstract class Rule {
	
	protected String table;
	protected String command;
	protected String chain;
	protected HashMap<String, String> options;
	
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("iptables -t " + this.table + " " + this.command + " " + this.chain);
		for (Map.Entry<String, String> entry : options.entrySet()) {
			builder.append(" ");
			builder.append(entry.getKey());
			builder.append(" ");
			builder.append(entry.getValue());
		}
		
		return builder.toString();
	}
	
	public void addOption(String name, String value) {
		options.put(name, value);
	}
	
	public void removeAllOptions() {
		options.clear();
	}

	public String getTable() {
		return table;
	}

	public void setTable(String table) {
		this.table = table;
	}

	public String getCommand() {
		return command;
	}

	public void setCommand(String command) {
		this.command = command;
	}

	public String getChain() {
		return chain;
	}

	public void setChain(String chain) {
		this.chain = chain;
	}

	public HashMap<String, String> getOptions() {
		return options;
	}

	public void setOptions(HashMap<String, String> options) {
		this.options = options;
	}
	
	
	
}
